//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.finance;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PayAliDao;
import com.aidong.model.wills.PayAli;
import com.aidong.service.AliPayService;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"payAli"})
public class PayAliController extends BaseController {
    @Resource
    PayAliDao payAliDao;
    @Resource
    protected AliPayService aliPayService;

    public PayAliController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("finance/payali/list")).addObject("payaliStatus", this.getTypeList("payaliStatus")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("status", status);
        if(!this.chkNull(dateFrom)) {
            cd.ge("createTime", this.getDateFrom(dateFrom));
        }

        if(!this.chkNull(dateTo)) {
            cd.le("createTime", this.getDateTo(dateTo));
        }

        this.payAliDao.queryPageList(pg, cd, (new OrderSet()).desc("createTime"));
        ModelAndView mv = new ModelAndView("finance/payali/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "shopCode", shopCode);
            cd.eq("status", status);
            if(!this.chkNull(dateFrom)) {
                cd.ge("createTime", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("createTime", this.getDateTo(dateTo));
            }

            this.payAliDao.queryPageList(e, cd, (new OrderSet()).desc("createTime"));
            ExportXls xls = new ExportXls(response, "支付宝支付流水", "支付宝支付流水");
            xls.addHead(new String[]{"门店编号", "门店名称", "时间", "条码", "金额", "状态", "付款时间", "付款人帐号", "支付单号", "支付宝序号", "支付流水号", "销售员1", "销售员2", "操作员"});
            xls.setWidth(new int[]{10, 10, 20, 20, 10, 10, 20, 20, 22, 30, 10, 15, 15, 15});
            new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(e.getResultList() != null) {
                Iterator i$ = e.getResultList().iterator();

                while(i$.hasNext()) {
                    PayAli pay = (PayAli)i$.next();
                    xls.addRow(new Object[]{pay.getShopCode(), this.cache.getValue("shopName", pay.getShopCode()), sdf2.format(pay.getCreateTime()), pay.getBarCode(), pay.getAmount(), this.cache.getValue("payaliStatus", String.valueOf(pay.getStatus())), pay.getPayTime() == null?null:sdf2.format(pay.getPayTime()), pay.getPayUser(), pay.getTradeNo(), pay.getAlipayNo(), pay.getPayListId(), this.nvl(pay.getSalesCode()) + " - " + this.nvl(this.cache.getValue("salesName", pay.getSalesCode())), this.nvl(pay.getSalesCode2()) + " - " + this.nvl(this.cache.getValue("salesName", pay.getSalesCode2())), this.nvl(pay.getCreateUser()) + " - " + this.nvl(this.cache.getValue("userName", pay.getCreateUser()))});
                }
            }

            xls.close();
            this.addUserLog("导出支付宝支付流水", e.getResultList().size() + "条记录");
        } catch (Exception var13) {
            this.log.error("import", var13);
        }

        return null;
    }

    @RequestMapping({"query"})
    @ResponseBody
    public String query(@RequestParam("id") int id) {
        PayAli payAli = (PayAli)this.payAliDao.getById(Integer.valueOf(id));
        if(payAli != null) {
            if(payAli.getStatus().intValue() == 1) {
                return this.getResult(false, "该条码已支付");
            } else if(payAli.getStatus().intValue() == 2) {
                return this.getResult(false, "该条码已完成支付");
            } else if(payAli.getStatus().intValue() != 3 && payAli.getStatus().intValue() != 4) {
                if(payAli.getStatus().intValue() == 0) {
                    StringBuilder msg = new StringBuilder();
                    HashMap rep = new HashMap();
                    int ret = this.aliPayService.queryPay(payAli.getTradeNo(), rep, msg);
                    if(ret > 0) {
                        payAli.setStatus(Integer.valueOf(ret));
                        payAli.setPayTime(new Date());
                        payAli.setAlipayNo((String)rep.get("trade_no"));
                        payAli.setPayUser((String)rep.get("buyer_logon_id"));
                        this.payAliDao.updatePayStatus(payAli);
                    }
                }

                return this.getSuccess("", payAli.getStatus().intValue() == 0?"未支付":"操作成功");
            } else {
                return this.getResult(false, "该条码已取消支付");
            }
        } else {
            return this.getResult(false, "没有这个支付条码");
        }
    }
}
